package com.ruoyi.weixin.untils;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import java.util.List;

public  class PageListUtils {
    public static <T> IPage<T> listToPage(List<T> list, Integer current, Integer size){
        IPage<T> iPage = new Page<>(current,size);
        iPage.setTotal(list.size());
        int startIndex = (int)((current - 1)*size);
        if(null == list || list.isEmpty() || startIndex > list.size()){
            iPage.setRecords(null);
        }
        else {
            int toIndex = (int)(current*size);
            iPage.setRecords(list.subList(startIndex,toIndex > list.size() ? list.size() : toIndex));
        }
        return iPage;
    }
}